import actionTypes from "./addressActionType";

const initState = {
    requestAddressParams: {
        index: 1,
        num: 10,
        collegeAreaId: "",
        building: "",
        unit: ""
    },
    tableData: {
        data: [],
        count: 0,
        total:0
    },
    campusselect:[],
    errorTableData:
        {
            data:[],
            count:0
        },
    campustable:{
        data:[],
        count:0,
        total:0
    },
    college_select:[]
};

const addressReduers = (state = initState, action: any) => {
    switch (action.type) {
        //改变请求参数
        case actionTypes.SET_ADDRESS_PARAMS:
            return {
                ...state,
                requestAddressParams: {
                    ...state.requestAddressParams,
                    ...action.payload
                }
            };
            //如果请求地址数据成功，就会把数据推到tableData
        case actionTypes.GET_ADDRESS:
            return{
                ...state,
                tableData:{
                    data:action.payload.data,
                    count:action.payload.count,
                    total:action.payload.total
                }
            };
        //如果请求地址数据成功，就会把数据推到tableData
        case actionTypes.GET_CAMPUS:
            return{
                ...state,
                campusselect:action.payload,
            };
        //如果注册审核返回成功就把数据存在全局变量里面
        case actionTypes.GET_CAMPUS_TABLE:
            return{
                ...state,
                campustable:{
                    data:action.payload.data,
                    count:action.payload.count,
                    total:action.payload.total
                }
            };
        //如果请求地址数据成功，就会把数据推到tableData
        case actionTypes.GET_COLLEGE_SELECT:
            return{
                ...state,
                college_select:action.payload,
            };
        default : return state;
    }
};
export default addressReduers;
